﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>发型数据表格</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="../demo.css" rel="stylesheet" type="text/css" />

    <script src="../../scripts/boot.js" type="text/javascript"></script>
</head>
<body>
<h1>预约信息</h1>

<div style="width: 800px;">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <!--<a class="mini-button"-->
                    <!--iconCls="icon-add" onclick="add()">增加</a> -->
                    <a class="mini-button"
                       iconCls="icon-add" onclick="edit()">确定</a>

                </td>
                <!--<td style="white-space: nowrap;"><input id="key"-->
                <!--class="mini-textbox" emptyText="请输入流水号" style="width: 150px;"-->
                <!--onenter="onKeyEnter" /> <a class="mini-button" onclick="search()">查询</a>-->
                <!--</td>-->
            </tr>
        </table>
    </div>
</div>
<div id="datagrid1" class="mini-datagrid"
     style="width: 800px; height: 280px;" allowResize="true"
     url="../../order" idField="id"
     multiSelect="true">
    <div property="columns">
        <div type="checkcolumn"></div>
        <div field="id" width="50" headerAlign="center" allowSort="true">流水号</div>
        <div field="barberid" width="50" headerAlign="center"
             allowSort="true">理发师编号</div>
        <div field="customerid" width="50" headerAlign="center"
             allowSort="true">顾客编号</div>
        <div field="status" width="50" headerAlign="center" allowSort="true" renderer="onStatusRenderer">状态</div>
        <div field="begintime" width="120" headerAlign="center"
             allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss">开始时间</div>

        <div field="endtime" width="120" headerAlign="center"
             allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss">结束时间</div>
        <div field="styleid" width="50" headerAlign="center"
             allowSort="true">发型</div>

    </div>
</div>


<script type="text/javascript">
    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load();
    grid.sortBy("id", "asc");


    function add() {

        mini.open({
            url: bootPATH + "../demo/CommonLibs/OrderWindow.html",
            title: "新增发型", width: 600, height: 400,
            onload: function () {
                var iframe = this.getIFrameEl();
                var lifaorder = { action: "insert"};
                // iframe.contentWindow.SetData(data);????
                iframe.contentWindow.SetData(lifaorder);
            },
            ondestroy: function (action) {

                grid.reload();
            }
        });
    }
    //
    // function getbarber() {
    //
    //  var row = grid.getSelected();
    //      if (row) {
    //        mini.open({
    //           url: bootPATH + "../demo/CommonLibs/OrderWindow.html",
    //              title: "编辑发型", width: 600, height: 400,
    //              onload: function () {
    //                  var iframe = this.getIFrameEl();
    //                  var data = { action: "getallbarber",orderdata: JSON.stringify(row)};
    //                  iframe.contentWindow.SetData(data);
    //
    //              },
    //              ondestroy: function (action) {
    //                  grid.reload();
    //
    //              }
    //          });
    //
    //     } else {
    //          alert("请选中一条记录");
    //    }
    //
    //  }

    function edit() {
        var row = grid.getSelected();
        if (row) {
            row.oldid=row.id
            console.log(row)
            console.log(typeof row)

            mini.open({
                url: bootPATH + "../demo/CommonLibs/BarberOrderWindow.html",
                title: "编辑发型", width: 600, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "update", orderdata: JSON.stringify(row) };//标名字Data数据转字符串
                    iframe.contentWindow.SetData(data);

                },
                ondestroy: function (action) {
                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }
    }
    function remove() {

        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            if (confirm("确定删除选中记录？")) {
                var ids = [];
                for (var i = 0, l = rows.length; i<l; i++) {
                    var r = rows[i];
                    console.log(r);
                    ids.push(r.id);
                }
                var id = ids.join(',');
                alert(id)
                grid.loading("操作中，请稍后......");
                $.ajax({
                    url: "../../order/delete",
                    data:{
                        ids:id},
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        } else {
            alert("请选中一条记录");
        }
    }

    // function SetData(data) {
    //     method=data.action
    //     if (data.action == "update" || data.action == "order"||data.action == "cancel") {
    //
    //         //跨页面传递的数据对象，克隆后才可以安全使用
    //         data = mini.clone(data);
    //         var  styledata=data.styledata
    //         console.log(styledata)
    //         console.log(typeof styledata)//字符串
    //         styledata=JSON.parse(styledata)
    //         grid.setData(styledata)
    //
    //     }
    // }
    function search() {
        var key = mini.get("key").getValue();
        grid.load({ key: key });
    }
    function onKeyEnter(e) {
        search();
    }
    /////////////////////////////////////////////////
    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd');
        return "";
    }
    function onMarriedRenderer(e) {
        if (e.value == 1) return "是";
        else return "否";
    }
    var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
    var statu = [{ id:0, text: '预定' }, { id:1, text: '进行中'}, { id:2, text: '理发完成'}, { id:3, text: '取消预约'}];

    function onStatusRenderer(e) {
        for (var i = 0, l = statu.length; i < l; i++) {
            var g = statu[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }





</script>

<div class="description">
    <h3>Description</h3>

</div>
</body>
</html>